from pydantic import Field
from sqlalchemy import Column, Integer, String, DateTime, BigInteger, Text
from core.curd import Base
from datetime import datetime


class SysLog(Base):
    """
    操作日志记录
    """
    __tablename__ = 'sys_log'

    id = Column(BigInteger, primary_key=True, autoincrement=True, comment='日志主键')
    ip = Column(String(128, collation='utf8_general_ci'), nullable=True, default='', comment='主机地址')
    log_type = Column(String(1, collation='utf8_general_ci'), nullable=True, default='0', comment='0：登录 1：操作 2：消息 3：警告 4：错误 5：调试')
    login_status = Column(Integer, default=0, comment='登录状态 1：成功 0:失败')
    user_agent = Column(String(255, collation='utf8_general_ci'), nullable=True, default='', comment='User Agent')
    address = Column(String(255, collation='utf8_general_ci'), nullable=True, default='', comment='操作地点')
    create_time = Column(DateTime, nullable=True, default=datetime.now(), comment='访问时间')
    result_msg = Column(String(250, collation='utf8_general_ci'), nullable=True, default='', comment='返回消息')
    username = Column(String(50, collation='utf8_general_ci'), nullable=True, default='', comment='用户账号')
    business_type = Column(Integer, default=0, comment='操作信息 1新增 2修改 3删除 4授权 5导出 6导入 7强退 8生成代码 9清空数据 10其它 11：登录 12：退出 ')
    user_id = Column(Integer, default=0, comment='用户ID')
    title = Column(String(50, collation='utf8_general_ci'), nullable=True, default='', comment='模块标题')
    module = Column(String(100, collation='utf8_general_ci'), nullable=True, default='', comment='模块名')
    req_uri = Column(String(50, collation='utf8_general_ci'), nullable=True, default='', comment='模块标题')
    req_method = Column(String(50, collation='utf8_general_ci'), nullable=True, default='', comment='模块标题')
    req_params = Column(Text,  nullable=True, default='', comment='模块标题')
    duration = Column(Integer, default=0, comment='执行时长 毫秒')



